package com.itheima.demo.my_set;

public class Student implements Comparable<Student> {//定义学生类实现比较接口
    private String name;
    private int age;

    @Override
    public int compareTo(Student o) {//按年龄比较，年龄一样按名字字母比较
        //o为已存入元素
        int result = this.age - o.age;
        result = result == 0 ? this.name.compareTo(o.getName()) : result;
        return result;
    }

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
